package com.jzoom.zoom.token;

import com.jzoom.zoom.token.hex.ClientToken;
import com.jzoom.zoom.token.hex.HexToken;

import java.util.concurrent.TimeUnit;


public class TokenService {

	private HexToken hexToken;
	
	public TokenService() {
		this("Zoom");
	}
	
	public TokenService(String name) {
		hexToken = new HexToken( name.getBytes() );
	}

	public String generateToken(String userId, String role) {
		return hexToken.encode(TokenUtil.createToken(userId, role, 12, TimeUnit.HOURS));
	}

	public ClientToken verifyToken(String token) {
		if(token==null || token.isEmpty()) {
			return null;
		}
		return hexToken.decode(token);
	}
	
}
